<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datetimepicker\DateTimePicker;//时间
use common\models\project\Project;

/* @var $this yii\web\View */
/* @var $model common\models\projectrepo\ProjectRepo */
/* @var $form yii\widgets\ActiveForm */
?>

<?=Html::jsFile('@web/js/angular.min.js')?>

<div class="project-repo-form" ng-controller="menuDesigner">

    <?php $form = ActiveForm::begin(); ?>

    <div class="row">
        <div class="col-md-2">
            <?= $form->field($model, 'number')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'category')->dropDownList(Project::getArrayCategory()) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'firstname')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'secondname')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'repo_unit')->textInput(['maxlength' => true]) ?>
        </div>
    </div>

    <div class="row">
        <div class="col-md-2">
            <?= $form->field($model, 'contacts')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'telephone')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'mobile_phone')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <div>
                <div class="form-group field-classteam-starttime required" style="width: 250px">
                    <label class="control-label" for="classteam-starttime">申请日期</label>
                    <?= DateTimePicker::widget([
                        'model' => $model,
                        'attribute' => 'application_date',
                        'language' => 'zh-CN',
                        'size' => 'ms',
                        'clientOptions' => [
                            'autoclose' => true,
                            'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                            'todayBtn' => true
                        ]
                    ]);?>
                </div>
            </div>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'fill_instructions')->textInput(['maxlength' => true]) ?>
        </div>
    </div>
    
    <div class="row">
        <div class="col-md-2">
            <div class="span">
            <h3>
                项目负责人
            </h3>
            </div>
        </div>
        <div class="col-md-10">
            <div class="row">
                <div class="col-md-2">
                    <?= $form->field($model, 'leader_name')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'leader_mobile')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'leader_email')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-6">
                    <?= $form->field($model, 'leader_profession')->textInput(['maxlength' => true]) ?>
                </div>
            </div>

        </div>
    </div>

    <div class="row">
        <div class="col-md-2">
            <div class="span">
            <h3>
                联系人
            </h3>
            </div>
        </div>
        <div class="col-md-10">
            <div class="row">
                <div class="col-md-2">
                    <?= $form->field($model, 'contact_name')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'contact_mobile')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'contact_email')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'contact_address')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'contact_fax')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'contact_telephone')->textInput(['maxlength' => true]) ?>
                </div>
            </div>

        </div>
    </div>

    <div class="row">
        <div class="col-md-2">
            <div class="span">
            <h3>
                合作单位
            </h3>
            </div>
        </div>
        <div class="col-md-10">
            <div class="row">
                <div class="col-md-2">
                    <?= $form->field($model, 'coop_name')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'coop_leader')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'coop_telephone')->textInput(['maxlength' => true]) ?>
                </div>                    
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-2">
            <div class="span">
            <h3>
                申报单位情况
            </h3>
            </div>
        </div>
        <div class="col-md-10">
            <div class="row">
                <div class="col-md-2">
                    <?= $form->field($model, 'repo_unitname')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'repo_supervisor')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-md-2">
                    <?= $form->field($model, 'repo_leadername')->textInput(['maxlength' => true]) ?>
                </div>                    
                <div class="col-md-2">
                    <?= $form->field($model, 'repo_property')->textInput(['maxlength' => true]) ?>
                </div>                    
            </div>
            <div class="row">
                <div class="col-md-12">
                    <?= $form->field($model, 'repo_profile')->textInput(['maxlength' => true]) ?>
                </div>
            </div>
        </div>
    </div>    

    <div class="row">
        <div class="col-md-12">
            <?= $form->field($model,'background')->widget('kucha\ueditor\UEditor',[]) ?>
        </div>
    </div>
    
    <div class="row">
        <div class="col-md-12">
            <?= $form->field($model,'main_contents')->widget('kucha\ueditor\UEditor',[]) ?>
        </div>
    </div>
    
    <div class="row">
        <div class="col-md-12">
            <?= $form->field($model,'existing_basis')->widget('kucha\ueditor\UEditor',[]) ?>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <?= $form->field($model,'expected_results')->widget('kucha\ueditor\UEditor',[]) ?>
        </div>
    </div>

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>实施阶段</th>
                <th>目标内容</th>
                <th>起止时间</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <?php if(is_array($model->schedule_target)) { ?>
            <?php foreach ($model->schedule_target as $k=>$t) { ?>

            <tr class="tplschedule">
                <td>
                    
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[schedule_target][]" value="<?= $t ?>"/>
                </td>
                <td>
                    <div class="row">
                        <div class="col-md-6">
                            <input type="text" name="ProjectRepo[schedule_starttime][]" value="<?= $model->schedule_starttime[$k] ?>" id="starttime<?= $k ?>">
                        </div>
                        <div class="col-md-6">
                            <input type="text" name="ProjectRepo[schedule_endtime][]" value="<?= $model->schedule_endtime[$k] ?>" id="endtime<?= $k ?>">
                        </div>
                    </div>
                <td>
                    <button style="margin-top: 24px;<?php if ($k == 0) { ?>display: none<?php } ?>" class="btn btn-warning btn-sm" type="button" id="delschedule">删除</button>
                    <button style="margin-top: 24px;<?php if ($k != 0) { ?>display: none<?php } ?>" class="btn btn-info btn-sm addschedule" ng-click="addschedule();" type="button">添加</button>
                </td>
            </tr>


            <?php } ?>
            <?php } else { ?>


            <tr class="tplschedule">
                <td>
                    
                </td>
                <td>
                    <?= $form->field($model, 'schedule_target[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group field-classteam-starttime required" style="width: 300px">
                                <label class="control-label" for="classteam-starttime">开始时间</label>
                                <?= DateTimePicker::widget([
                                    'model' => $model,
                                    'attribute' => 'schedule_starttime[]',
                                    'language' => 'zh-CN',
                                    'size' => 'ms',
                                    'clientOptions' => [
                                        'autoclose' => true,
                                        'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                                        'todayBtn' => true
                                    ]
                                ]);?>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group field-classteam-starttime required" style="width: 300px">
                                <label class="control-label" for="classteam-starttime">结束时间</label>
                                <?= DateTimePicker::widget([
                                    'model' => $model,
                                    'attribute' => 'schedule_endtime[]',
                                    'language' => 'zh-CN',
                                    'size' => 'ms',
                                    'clientOptions' => [
                                        'autoclose' => true,
                                        'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                                        'todayBtn' => true
                                    ]
                                ]);?>
                            </div>
                        </div>
                    </div>
                <td>
                    <button style="margin-top: 24px;display: none" class="btn btn-warning btn-sm" type="button" id="delschedule">删除</button>
                    <button style="margin-top: 24px;" class="btn btn-info btn-sm addschedule" ng-click="addschedule();" type="button">添加</button>
                </td>
            </tr>
            <?php } ?>

        </tbody>
    </table>

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>序号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>职务职称</th>
                <th>工作单位</th>
                <th>在本项目中承担的主要工作</th>
                <th>备注</th>
                <th></th>
            </tr>
        </thead>
        <tbody>

            <?php if(is_array($model->mainpart_name)) { ?>
            <?php foreach ($model->mainpart_name as $k=>$t) { ?>

            <tr class="tplmainpart">
                <td>

                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[mainpart_name][]" value="<?= $t ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[mainpart_age][]" value="<?= $model->mainpart_age[$k] ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[mainpart_profession][]" value="<?= $model->mainpart_profession[$k] ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[mainpart_unit][]" value="<?= $model->mainpart_unit[$k] ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[mainpart_mainwork][]" value="<?= $model->mainpart_mainwork[$k] ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[mainpart_note][]" value="<?= $model->mainpart_note[$k] ?>"/>
                </td>
                <td>
                    <button style="margin-top: 24px;<?php if ($k == 0) echo 'display: none';?>" class="btn btn-warning btn-sm" type="button" id="delmainpart">删除</button>
                    <button style="margin-top: 24px;<?php if ($k != 0) echo 'display: none';?>" class="btn btn-info btn-sm addmainpart" ng-click="addmainpart();" type="button">添加</button>
                </td>
            </tr>

            <?php } ?>
            <?php } else { ?>


            <tr class="tplmainpart">
                <td>

                </td>
                <td>
                    <?= $form->field($model, 'mainpart_name[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <?= $form->field($model, 'mainpart_age[]')->textInput() ?>
                </td>
                <td>
                    <?= $form->field($model, 'mainpart_profession[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <?= $form->field($model, 'mainpart_unit[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <?= $form->field($model, 'mainpart_mainwork[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <?= $form->field($model, 'mainpart_note[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <button style="margin-top: 24px;display: none" class="btn btn-warning btn-sm" type="button" id="delmainpart">删除</button>
                    <button style="margin-top: 24px" class="btn btn-info btn-sm addmainpart" ng-click="addmainpart();" type="button">添加</button>
                </td>
            </tr>
            <?php } ?>
        </tbody>
    </table>
    
    <div class="row">
        <div class="col-md-2">
             <?= $form->field($model, 'total_budget')->textInput() ?>
        </div>
        <div class="col-md-2">
             <?= $form->field($model, 'apply_budget')->textInput() ?>
        </div>
        <div class="col-md-2">
             <?= $form->field($model, 'own_budget')->textInput() ?>
        </div>
        <div class="col-md-2">
             <?= $form->field($model, 'nation_budget')->textInput() ?>
        </div>
        <div class="col-md-2">
             <?= $form->field($model, 'unit_budget')->textInput() ?>
        </div>
        <div class="col-md-2">
             <?= $form->field($model, 'other_budget')->textInput() ?>
        </div>
    </div>

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>编号</th>
                <th>支出内容</th>
                <th>金额</th>
                <th>备注</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <?php if(is_array($model->paid_content)) { ?>
            <?php foreach ($model->paid_content as $k=>$t) { ?>

            <tr class="tplpaid">
                <td>
                    
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[paid_content][]" value="<?= $t ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[paid_money][]" value="<?= $model->paid_content[$k] ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectRepo[paid_note][]" value="<?= $model->paid_note[$k] ?>"/>
                </td>                
                <td>
                    <button style="margin-top: 24px;<?php if ($k == 0) { ?>display: none<?php } ?>" class="btn btn-warning btn-sm" type="button" id="delpaid">删除</button>
                    <button style="margin-top: 24px;<?php if ($k != 0) { ?>display: none<?php } ?>" class="btn btn-info btn-sm addpaid" ng-click="addpaid();" type="button">添加</button>
                </td>
            </tr>

            <?php } ?>
            <?php } else { ?>

            <tr class="tplpaid">
                <td>
                    
                </td>
                <td>
                    <?= $form->field($model, 'paid_content[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <?= $form->field($model, 'paid_money[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <?= $form->field($model, 'paid_note[]')->textInput(['maxlength' => true]) ?>
                </td>                
                <td>
                    <button style="margin-top: 24px;display: none" class="btn btn-warning btn-sm" type="button" id="delpaid">删除</button>
                    <button style="margin-top: 24px" class="btn btn-info btn-sm addpaid" ng-click="addpaid();" type="button">添加</button>
                </td>
            </tr>
            <?php } ?>
        </tbody>
    </table>


    <?= $form->field($model, 'calculation_basis')->widget('kucha\ueditor\UEditor',[]) ?>

    <?= $form->field($model, 'repo_option')->widget('kucha\ueditor\UEditor',[]) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>


<?php $this->beginBlock('footer_scripts'); ?>

<script>
    angular.module('app', []).controller('menuDesigner', function ($scope, $http) {
        //实施阶段
        var schedulelength = 1;
        $("body").on("click", ".addschedule", function() {

            schedulelength +=1;
            
            var clone = $(this).parent().parent().clone();
            clone.find('button').eq(1).hide();
            clone.find('button').eq(0).show();
            $(this).parent().parent().parent().append(clone);
        });

        $("body").on("click", "#delschedule", function() {
            schedulelength -=1;
            $(this).parents(".tplschedule").remove();
        });

        //主要参加人员
        var mainpartlength = 1;
        $("body").on("click", ".addmainpart", function() {

            mainpartlength +=1;
            
            var clone = $(this).parent().parent().clone();
            clone.find('button').eq(1).hide();
            clone.find('button').eq(0).show();
            $(this).parent().parent().parent().append(clone);
        });

        $("body").on("click", "#delmainpart", function() {
            mainpartlength -=1;
            $(this).parents(".tplmainpart").remove();
        });

        //支出
        var paidlength = 1;
        $("body").on("click", ".addpaid", function() {

            paidlength +=1;
            
            var clone = $(this).parent().parent().clone();
            clone.find('button').eq(1).hide();
            clone.find('button').eq(0).show();
            $(this).parent().parent().parent().append(clone);
        });

        $("body").on("click", "#delpaid", function() {
            paidlength -=1;
            $(this).parents(".tplpaid").remove();
        });
    });
    angular.bootstrap(document, ['app']);
</script>
<script>
    $(document).ready(function(){
        <?php if(is_array($model->schedule_target)) { ?>
        <?php foreach ($model->schedule_target as $k=>$t) { ?>
        $('#starttime<?= $k ?>').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
        $('#endtime<?= $k ?>').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
        <?php } ?>
        <?php } ?>
    });
</script>
<?php $this->endBlock(); ?>